package iSOCK::Controller::Specification::Commit;

use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller' }

use SOCK::LOG;

=head1 NAME

iSOCK::Controller::Specification::Commit - Subversion Controller for iSOCK

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

sub index :Path :Args(0) {
  my ( $self, $c ) = @_;
  
  my $parameters = $c->request->parameters;
  
  if ( $c->request->method eq 'POST' && $parameters->{form_subversion_submit} ) {
    my $session      = $c->session;
    my $session_id   = $c->sessionid;
    my $session_path = iSOCK::Controller::Root->session_path ( $c );
    my $log          = SOCK::LOG->new ({ file => "$session_path/isock_subversion.log", fatality => 0 });

    $log->say_n_right ( "Processing within $session_id session..." );

    $c->model ( 'Session' )->commit_integration ({ c => $c, log => $log });

    $log->left_n_say ( "Done." );

    $log->close;
    
    $c->response->redirect ( $c->uri_for ( '/specification/logs' ) );
  }
  else {
    my @time = localtime time;

    $c->stash ( default_milestone_value => sprintf 'changeme-%04d%02d%02d', 1900 + $time[5], $time[4], $time[3] );
    
    $c->forward ( qw( iSOCK::Controller::Root render_view ) );
  }
}

sub end : ActionClass('RenderView') {}

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
